/*封装与部门信息的ajax查询，更改等*/
require.config({
    paths: {
        "common": "../common/common"
    }
});
define(['common'], function(common) {
    var baseUrl = common.defaultStr();

    function queryDepts(query) {
        return $.ajax({
            type: "POST",
            url: baseUrl + '/base/dept/list.do',
            data: JSON.stringify(query),
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }

    function handleSessionTimeOut(data) {
        if (data && data.retcode === '202') {
            location.reload();
        }
    }

    function delDepts(query) {
        return $.ajax({
            type: "POST",
            url: baseUrl + '/base/dept/delete.do',
            data: JSON.stringify(query),
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }

    function addDepts(query) {
        return $.ajax({
            type: "POST",
            url: baseUrl + '/base/dept/add.do',
            data: JSON.stringify(query),
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }

    function updateDepts(query) {
        return $.ajax({
            type: "POST",
            url: baseUrl + '/base/dept/update.do',
            data: JSON.stringify(query),
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }
    return {
        queryDepts,
        addDepts,
        updateDepts,
        delDepts
    }
    // delDepts: delDepts,
    // addDepts: addDepts,
    // updateDepts: updateDepts

})
